<template>
	<div style="position: relative;">
		<Row>
	        <Col span="24"  style="text-align: center;">
	            <Card style="width:880px;margin: auto;">
	                <p slot="title"><slot></slot></p>
	                <Row >
				        <Col span="12" >
				        	<span>姓名：</span>
							<Input v-model="name" placeholder="请输入姓名" style="width:200px"></Input>
				        </Col>
				        <Col span="12" >
				        	<span>工号：</span>
							<Input v-model="no" placeholder="请输入工号" style="width:200px"></Input>
				        </Col>
				    </Row>
	                <Row style="text-align: center;margin-top:15px;">
					    <Col span="12" >
				        	<span>科目：</span>
				        	<Tooltip content="请到下面“科目筛选”改变科目" theme="light">
					        	<Select disabled v-model="importsubjectid" style="width:200px"  >
					        		<Option v-for="item in importsubjectlist" :key="item.value" :value="item.value">{{item.label}}</Option>
							    </Select>
						    </Tooltip>
				        </Col>
				        <!--<Col span="12">
				        	<span>教育程度：</span>
				        	<RadioGroup  v-model="eduselect" type="button" >
				        		<Radio v-for="item in edulist" :key="item.value" :label="item.value">{{item.label}}</Radio>
						       
						    </RadioGroup>
				        </Col>-->
			        </Row>
				    <Row>
				    	<Col span="24" style="margin-top:15px">
				    		<Button type="ghost" @click="chance" icon="close-round">取消</Button>
				    		<Button type="primary" @click="saveteacher" icon="checkmark-round">保存</Button>
				    	</Col>
				    </Row> 
				    
	            </Card>
	        </Col>
	    </Row>
	     <Spin size="large" fix v-if="loadingShow"></Spin>
	</div>
</template>

<script>
	import api from "@/components/js/Apidomain.js"
	
	export default{
		props:{
			importsubjectlist: {
		        type: Array,
		        default: function () {return []}
		   	},
			importsubjectid:"",		//父组件传来的科目的id
			importteacherid:"",		//父组件传来的teacherid
		},
		data(){
			return{
				loadingShow:false,			//控制面板的加载中的显示和隐藏
				
				name:"",						//新增老师的名字
				no:"",							//新增教师工号
				
				eduselect:"",					//教育水平
				subjectselect:"",				//选择科目
				edulist: [
//					{value: '1',label: '专科'},
//					{value: '2',label: '本科'},
//                  {value: '3',label: '硕士'}, 
//                  {value: '4',label: '博士'},
                ],
				subjectlist: [
//					{value: '1',label: '语文'},
//					{value: '2',label: '数学'},
//                  {value: '3',label: '英语'}, 
//                  {value: '4',label: '物理'},
//					{value: '5',label: '化学'},
//                  {value: '6',label: '生物'}, 
//                  {value: '7',label: '历史'},
//					{value: '8',label: '地理'},
//                  {value: '9',label: '政治'}, 
                ],
			}
		},
		created(){
			this.getlevellist();
			this.editteacher();

		},
		methods:{
			chance:function(){
				this.$emit('chance')
			},
			
			editteacher:function(){
				//如果等于空那么是新增年级，如果有的话则是编辑，拿id去取年级信息
				
				if(this.importteacherid == ""){
					return;
				}else{
					this.loadingShow = true;
					var self = this;
	            	let url = api.apidomain+'/tqes/web/tchTeacher/getTeacherInfo';
	            	this.$http.post(url, {id:this.importteacherid}).then(function(response) {
						if(response.data.success == true){
//							////console.log(response.data.data)
							
							self.name = response.data.data.name						//新增老师的名字
							self.no = response.data.data.no							//新增教师工号
							self.eduselect = response.data.data.level					//教育水平
							
							self.loadingShow = false;
							
		           }else if(response.data.success == false){
		            		self.$Message.error({
								content: response.data.msg,
								duration: 10,
								closable: true
							});	
				            self.loadingShow = false;
		            	}
		            	
					})
					.catch(function(error) {
						self.$Message.error({
							content: '系统发生错误：错误码00016',
							duration: 10,
							closable: true
						});
						self.loadingShow = false;
					});
				}
			},
			
			getlevellist:function(){
				this.loadingShow = true;
				var self = this;
            	let url = api.apidomain+'/tqes/web/tchTeacher/getEduSelect';
            	this.$http.post(url,{}).then(function(response) {
					if(response.data.success == true){
						
//						////console.log(response.data.data)
						self.edulist = response.data.data
						self.loadingShow = false;
		            }else if(response.data.success == false){
		            		self.$Message.error({
								content: response.data.msg,
								duration: 10,
								closable: true
							});						
		            		self.loadingShow = false;
		            	}
					})
					.catch(function(error) {
						self.$Message.error({
							content: '系统发生错误：错误码00017',
							duration: 10,
							closable: true
						});
						self.loadingShow = false;
					});
			},
			saveteacher:function(){
				if(this.importsubjectid == "" || this.no == "" || this.name == "" ){
					self.$Message.error({
								content: "请完善信息后再提交",
								duration: 10,
								closable: true
							});
					return;
				}
				if(this.importteacherid == ""){
					var teacherdata = {
						id:"",
						no:this.no,
						name:this.name,
						level:this.eduselect,
						subjectId:this.importsubjectid,
					}
				}else{
					var teacherdata = {
						id:this.importteacherid,
						no:this.no,
						name:this.name,
						level:this.eduselect,
						subjectId:this.importsubjectid,
					}
				}
				this.loadingShow = true;
				var self = this;
            	let url = api.apidomain+'/tqes/web/tchTeacher/addTeacher';
            	this.$http.post(url,teacherdata).then(function(response) {
					if(response.data.success == true){
						self.$Message.success({
		                    content: '保存成功',
		                    duration: 10,
		                    closable: true
               			})
						self.$emit('chance')
						self.loadingShow = false;
		            }else if(response.data.success == false){
		            		self.$Message.error({
								content: response.data.msg,
								duration: 10,
								closable: true
							});
		            		self.loadingShow = false;
		            	}
					})
					.catch(function(error) {
						self.$Message.error({
							content: '系统发生错误：错误码00018',
							duration: 10,
							closable: true
						});
						self.loadingShow = false;
					});
			},
			
			
		},
		watch:{
			importteacherid:function(newValue, oldValue){
				this.editteacher();
			}
		}
	}
</script>

<style>
</style>